// pages/laoLaiDetail/index.js
const apiPay = require('../../config/api.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        baseInfo: {},
        detailList: [],
    },
    getDataDetail(id) {
        wx.showLoading({ title: '正在加载' })
        this.setData({
            detailList: []
        })
        wx.request({
            url: apiPay.deadBeatCheckDetail,
            method: 'GET',
            data: {
                id: id
            },
            success: (res) => {
                wx.hideLoading();
                console.log('deadBeatCheckDetail',res)
                let data = res.data || {}
                if (data && data.code == '200' && data.data && data.data.length) {
                    let detailList = data.data
                    this.setData({
                        detailList: detailList || []
                    })
                } else {
                    wx.showToast({
                        title: data.msg || "网络异常！"
                    })
                }

            },
            fail: (res) => {
                wx.hideLoading();
            }
        })
    },
    toPay(fee) {
        let this_ = this;
        let openid = wx.getStorageSync('openid')
        wx.request({
            url: apiPay.wxPay,
            method: 'GET',
            data: {
                openid: openid,
                amount: fee,
                description: '搜老赖失信记录',
                vipGradeId: -1
            },
            success: (res) => {
                wx.hideLoading();
                if (res.data.code == 200) {
                    this_.setData({
                        param: res.data.data
                    })
                    this_.pay(JSON.parse(res.data.data))
                } else {
                    wx.showToast({
                        title: "网络异常！"
                    })
                }

            },
            fail: (res) => {

                wx.hideLoading();
            }
        })
    },
    //支付
    pay: function (param) {
        var that = this;
        wx.requestPayment({
            timeStamp: param.timeStamp,
            nonceStr: param.nonceStr,
            package: param.package,
            signType: param.signType,
            paySign: param.paySign,
            success: function (res) {
                //收费结束--调用接口详情
                if (that.data.baseInfo && that.data.baseInfo.Id) {
                    // 去收费
                    that.getDataDetail(that.data.baseInfo.Id)
                }
            },
            fail: function (res) { },
            complete: function (res) { }
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        if (options && options.data) {
            this.setData({
                baseInfo: JSON.parse(options.data)
            })
        }
        if (this.data.baseInfo && this.data.baseInfo.Id) {
            // 去收费
            this.toPay(this.data.baseInfo.deadBeatCheck)
        }
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})